Skip to content
This repository has been archived by the owner on Sep 1, 2020. It is now read-only.

Latest commit

 

History

History
13 lines (11 loc) · 754 Bytes

6.2.3 - swoole_buffer->substr.md

File metadata and controls

13 lines (11 loc) · 754 Bytes

swoole_buffer->substr

从缓冲区中取出内容。

string swoole_buffer->substr(int $offset, int $length = -1, bool $remove = false);
  • $offset 表示偏移量,如果为负数,表示倒数计算偏移量
  • $length 表示读取数据的长度,默认为从 $offset 到整个缓存区末尾
  • $remove 表示从缓冲区的头部将此数据移除。只有 $offset = 0 时此参数才有效

swoole_buffer->substr() 会复制一次内存 (复制指定部分给返回值的字符串) $remove 后实际内存并没有释放,只是底层进行了指针偏移。当销毁此对象时才会真正释放内存 1.9.4及之后的版本里,swoole_buffer->substr() 能够在某些情况下触发 swoole_buffer->recycle()